package com.ts.view

import android.content.Context
import android.opengl.GLSurfaceView
import android.util.AttributeSet
import android.util.Log
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

class MyGlSurfaceView:GLSurfaceView, GLSurfaceView.Renderer {

        // Used to load the 'audiocamera' library on application startup.
//        init {
//            System.loadLibrary("audiocamera")
//        }

//    var vertexBuffer =
//        ByteBuffer.allocateDirect(4 * 4 * 2).order(ByteOrder.nativeOrder()).asFloatBuffer()

    constructor(context:Context):super(context){
//        setRenderer(this)
//        renderMode = RENDERMODE_CONTINUOUSLY;
//        vertexBuffer.clear()
//        vertexBuffer.put(VERTEX)


    }

    constructor(context:Context ,attrs: AttributeSet):super(context,attrs){
        setEGLContextClientVersion(2)
        setRenderer(this)

        renderMode = RENDERMODE_WHEN_DIRTY;
    }

    override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
        Log.e("ByteFlow","native_OnSurfaceCreated")
        native_OnSurfaceCreated()
    }

    override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
        native_OnSurfaceChanged(width,height)
    }

    override fun onDrawFrame(gl: GL10?) {
        native_OnDrawFrame()
    }



    external fun native_SetImageData(format:Int ,width: Int ,height: Int ,byteArray: ByteArray)

    external fun native_Init();
    external fun native_OnDrawFrame()
    external fun native_OnSurfaceChanged(width: Int,height: Int)
    external fun native_OnSurfaceCreated();

}